package org.fujay.langchain4jserver.application.assembler;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.fujay.langchain4jserver.application.dto.ModelDTO;
import org.fujay.langchain4jserver.application.dto.ModelSummaryDTO;
import org.fujay.langchain4jserver.domain.model.aggregate.Model;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 模型聚合 与 DTO 之间的转换器
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ModelAssembler {

    public static ModelSummaryDTO toSummaryDTO(final Model model) {
        if (model == null) {
            return null;
        }
        return ModelSummaryDTO.builder()
                .id(model.getId().value())
                .modelName(model.getModelName())
                .modelType(model.getModelType().name())
                .supplierName(model.getSupplier().supplierName())
                .enabled(model.isEnabled())
                .build();
    }

    public static List<ModelSummaryDTO> toSummaryDTOList(final List<Model> models) {
        if (models == null) {
            return Collections.emptyList();
        }
        return models.stream().map(ModelAssembler::toSummaryDTO).collect(Collectors.toList());
    }

    public static ModelDTO toDTO(final Model model) {
        if (model == null) {
            return null;
        }
        return ModelDTO.builder()
                .id(model.getId().value())
                .modelName(model.getModelName())
                .modelType(model.getModelType().name())
                .supplier(model.getSupplier())
                .config(model.getConfig())
                .enabled(model.isEnabled())
                .connectionStatus(model.getConnectionStatus())
                .build();
    }

    public static List<ModelDTO> toDTOList(final List<Model> models) {
        if (models == null) return List.of();
        return models.stream().map(ModelAssembler::toDTO).collect(Collectors.toList());
    }

    // TODO: Methods to convert Request DTOs to domain parameters if needed

}
